#if !defined(ximera_logger_hpp)
#define ximera_logger_hpp

// -----------------------------------------------------------

#include <ximera/types.hpp>
#include <iostream>

namespace ximera
{
    //! The macro for the global logger
    #define XIMERA_LOG() ximera::log

    //! A class for logging errors and information to an output stream
    class XIMERA_API Logger
    {
    public:
        explicit Logger(String const& fileName);
        explicit Logger(std::wostream* strm, bool ownStream = false);
        ~Logger();

        void fileName(String const& fileName);
        void stream(std::wostream* strm, bool ownStream = false);

        void clear();

        template <typename T>
        void write(T const& value) {
            if (_strm)
                *_strm << value;
        }

        operator void*() const {
            return (_strm && *_strm) ? reinterpret_cast<void*>(1) : 0;
        }

        friend Logger& operator<<(Logger& logger, std::wostream& (func)(std::wostream&))
        {
            if (logger._strm)
                *logger._strm << func;

            return logger;
        }

    private:
        std::wostream* _strm;
        bool _ownStream;
    };

    template <typename T>
    Logger& operator<<(Logger& logger, T const& value)
    {
        logger.write(value);
        return logger;
    }

    //! The global logger. By default, it logs to the file 'ximera.log'
    extern XIMERA_API Logger log;
}

// -----------------------------------------------------------

#endif